package com.jone.comic_api.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.framework.controller.AjaxResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jone.comic_api.entity.ComicChapter;

/**
 * <p>
 * 前端控制器
 * </p>
 * 
 * @author Yanghu
 * @since 2017-05-26
 */
@RestController
@RequestMapping("/comic/comicChapter")
public class ComicChapterController extends BaseController {

    @RequestMapping(value = "/getChapterList")
    public String getBookInfo(ComicChapter chapter) {
        Page<ComicChapter> page = getPage(10);
        return callback(new AjaxResult(chapter.selectPage(page,
                new EntityWrapper<ComicChapter>().eq("book_id", chapter.getBookId()).orderBy("id"))));
    }

    @RequestMapping(value = "/getChapterNext")
    public String getChapterNext(ComicChapter chapter) {
        return callback(new AjaxResult(chapter.selectOne(
                new EntityWrapper<ComicChapter>()
                .eq("book_id", chapter.getBookId())
                .gt("id", chapter.getId())
                .orderBy("id"))));
    }
    
    @RequestMapping(value = "/getChapterPrv")
    public String getChapterPrv(ComicChapter chapter) {
        return callback(new AjaxResult(chapter.selectOne(
                new EntityWrapper<ComicChapter>()
                .eq("book_id", chapter.getBookId())
                .lt("id", chapter.getId())
                .orderBy("id" , false))));
    }
}
